package thinking

object 集合操作 {
  def main(args: Array[String]): Unit = {

    val list = List(1, 2, 3, 4)
    val curList = list.map(i => i * 2)
    curList.foreach(println)

    //使用高阶函数
    val d = test(sum, 3.5)
    println(d)
    //scala允许将函数直接赋值给变量
    val fun = myPrint _
    //执行函数
    fun()

    //reduce
    val i = list.reduceLeft((a,b)=>a+b)

  }
  def myPrint(): Unit ={
    println("hello,world")
  }

  //高阶函数 (Double=>Double)函数的类型
  def test(f:Double=>Double,n1:Double):Double={
    f(n1)
  }
  def sum(n:Double):Double={
    n + n
  }

}
